<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>通过邀请码加入企业</title>
<%@ include file="/pages/wx/baseHead.jsp"%>
<!-- #cb60b3 -->
<style type="text/css">
.btn-my { background: #cb60b3; /* Old browsers */ 
background: -moz-linear-gradient(top, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* FF3.6+ */ 
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #cb60b3),color-stop(50%, #ad1283), color-stop(100%, #de47ac) ); /* Chrome,Safari4+ */ 
background : -webkit-linear-gradient( top, #cb60b3 0%,#ad1283 50%, #de47ac 100%); /* Chrome10+,Safari5.1+ */ 
background: -o-linear-gradient(top, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* Opera 11.10+ */ 
background: -ms-linear-gradient(top, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* IE10+ */ 
background: linear-gradient(to bottom, #cb60b3 0%, #ad1283 50%, #de47ac 100%);/* W3C */ 
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#cb60b3',endColorstr='#de47ac', GradientType=0 ); /* IE6-9 */ }
.btn-my{ width: 100px; height: 100px; -moz-border-radius: 50%; -webkit-border-radius: 50%; border-radius: 50%; }
.btn-my { background: gray; color:#ffffff; }
</style>
</head>
<body onclick="stop();">

<div class="alert alert-info" role="alert"  onclick="stop();">
	<div class="input-group margin-bottom-sm form-inline has-success">
		<span class="input-group-addon"><i class="fa fa-microphone fa-fw"></i>&nbsp;</span>
		<%-- <form action="${urlBasePath }weixin/user/companyInvestInput.do" method="POST" id="theform" name="theform"> --%>
	  		<input class="form-control col-md-3" type="text" value="${code }" id="search" name="code" placeholder="请输入邀请码" style="height: 46px;z-index: 1;" >
	  	<!-- </form>	 -->
	  
	  <span class="input-group-addon"><a href="javascript:void(0);" onclick="searchCode();"><i class="fa fa-search fa-sm"></i></a></span>
	</div>
	<nav>
	  <ul class="pager" style="padding-top: -10em;">
	  	<button id="touchArea" type="button" class="btn btn-my">
	  		<i class="fa fa-microphone-slash fa-3x voiceCls"></i>
	  		<!-- <div>2"</div> -->
	  	</button>
	  	<div id="msg" style="height: 10px;display: block;padding-top: 10px;">语音搜索暂无法使用</div>
	  	
	  	<div style="padding-top: 25px;color: red;" id="errorMsgDiv">
		  	<c:if test="${merc == null && (code =='' || code == null) }">
	  		请输入邀请码查询
		  	</c:if>
		  	<c:if test="${merc == null && (code != null && code !='') }">
		  	请输入正确的邀请码
		  	</c:if>
	  	</div>
	  </ul>
	</nav>
</div>

<div class="bd" style="margin-top: -15px;">
    <div class="weui_panel weui_panel_access">
        <c:if test="${merc != null }">
        	<input type="hidden" id="invId" value="${invId }">
        	<div class="weui_panel_hd" style="font-size: 1.2em;">企业信息</div>
	        <div class="weui_panel_bd">
	            <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg form-inline">
	                <div class="weui_media_hd">
	                    <img class="weui_media_appmsg_thumb" style="width: 60px;height: 60px;border-radius:60px" src="${urlBasePath }images/qykd.png" alt="">
	                </div>
	                <div class="weui_media_bd">
	                    <h4 class="weui_media_title">${merc.mercName }</h4>
	                    <p class="weui_media_desc"><i class="fa fa-male fa-fw"></i>管理员：${merc.contact }</p>
	                    <p class="weui_media_desc"><i class="fa fa-location-arrow fa-fw"></i>地址：${merc.address }</p>
	                </div>
	                <div align="right" style="margin-right: 2px;">
	                    	<button href="javascript:;" onclick="applyJoinCfm('${merc.mercNo}');" class="weui_btn weui_btn_plain_primary weui_btn_mini "><i class="fa fa-sign-out fa-fw"></i>申请</button>
	                </div>
	            </a>
	        </div>
        </c:if>
    </div>
</div>

<div class="weui_tabbar" style="position: fixed;bottom: 0%;left: 0%;background-color:#04BE02;">
    <a href="${urlBasePath}weixin/user/companySearch.do" class="weui_tabbar_item weui_bar_item_on">
        <p class="weui_tabbar_label" style="line-height: 40px;font-size:1.2em;color: #ffffff">
        <i class="fa fa-search fa-sm"></i>&nbsp;查询周边企业</p>
    </a>
</div>
<div style="height: 40px;display: block;"></div>


<div class="weui_dialog_confirm" id="confimDiv" style="display: none;">
	   <div class="weui_mask"></div>
	   <div class="weui_dialog">
	       <div class="weui_dialog_hd"><strong class="weui_dialog_title1 weui_dialog_confirm_title">确定加入该企业吗？</strong></div>
	       <div class="weui_dialog_bd weui_dialog_confirm_bd">
	       	<textarea class="form-control" rows="3" placeholder="请填入备注" id="remark" style="display: none;"></textarea>
	       	<input type="hidden" id="mercNo">
	       </div>
	       <div class="weui_dialog_ft">
	           <a href="javascript:applyJoinCfmCcl();" class="weui_btn_dialog default weui_btn_confirm_dialog_cancel">取消</a>
	           <a href="javascript:applyJoinCfmOk();" class="weui_btn_dialog primary weui_btn_confirm_dialog_ok">确定</a>
	       </div>
	   </div>
</div>

<div class="pop">
    <i class="fa fa-home fa-lg popi"></i>
</div>

<!-- 引入微信样式代码提示工具开始 -->
<%@ include file="/pages/wx/wxClass.jsp"%>
<!-- 引入微信样式代码提示工具结束 -->
<%@ include file="/pages/wx/baseBottom.jsp"%>

<script type="text/javascript">
	var timeOutEvent=0;
	
	try {
		$(function(){
			$('#search').keydown(function(e)
				{
					if(e.keyCode==13)
					{
						searchCode();
					}
				});
			initWxSdk();
		});
	} catch (e) {
		alert(e);
	}
	
	
	function initWxSdkOk()
	{
		
		$("#touchArea")[0].style.background = '#04BE02';
		$("#msg").html('长按尝试语音输入');
		$(".voiceCls").removeClass('fa-microphone-slash');
		$(".voiceCls").addClass('fa-microphone');
		initTouch();
	}
	
	/*绑定Touch事件*/
	function initTouch()
	{
		$("#touchArea").on({
	        touchstart: function(e){
	            timeOutEvent = setTimeout("longPress()",500);
	         	e.preventDefault();
	        },
	        touchmove: function(){
	        	clearTimeout(timeOutEvent); 
	        	timeOutEvent = 0; 
	        },
	        touchend: function(){//按键结束
	        	clearTimeout(timeOutEvent); 
	        	return;//暂时取消这个事件。因为调用录音支行该事件就不支持了。
	            if(timeOutEvent!=0){
	                //alert("你这是点击，不是长按");
	                return;
	            }
	            stop();
	            return false; 
	        },
	        touchcancel:function(){
	        }
	    })
	}
	var recordIng = 0;
	/*长按的方法*/
	function longPress(){
	    timeOutEvent = 0; 
	    
	    $("#touchArea")[0].style.background = '#FF99CC';
	    try {
		    wx.startRecord();
		    $("#msg").html('正在录音,轻敲屏幕停止');
		    recordIng = 1;
		} catch (e) {
		}
	   
	} 
	function stop()
	{
		if(!wxsdk) return;
		if(recordIng == 0) return;
	    recordIng = 0;
		$("#msg").html('结束录音，长按尝试语音搜索');
	    $("#touchArea")[0].style.background = '#04BE02';
		wx.stopRecord({
		    success: function (res) {
		        wx.translateVoice({
		 		   localId: res.localId, // 需要识别的音频的本地Id，由录音相关接口获得
		 		    isShowProgressTips: 1, // 默认为1，显示进度提示
		 		    success: function (res) {
		 		        //return res.translateResult; // 语音识别的结果
		 		        $("#search").val(res.translateResult.replace('。','').replace('!',''));
		 		    }
		 		});
		    }
		});
	}
	/*申请加入*/
	function applyJoinCfm(mercNo)
	{
		$("#mercNo").val(mercNo);
		$("#confimDiv")[0].style.display = 'block';
	}
	/*确认加入*/
	function applyJoinCfmOk()
	{
		$("#confimDiv")[0].style.display = 'none';
		var url ='${urlBasePath }weixin/user/companyJoin.do';
		var mercNo = $("#mercNo").val();
		//var remark = $("#remark").val();
		var invId = $("#invId").val();
		$.ajax({
			url:url,
			data:{
				mercNo:mercNo,
				//remark:remark,
				invId:invId
			},
			async:true,
			success:function(ret){
				if(ret.code == '0')
				{
					openToast("加入成功");
					
					setTimeout("goPage(1)",1000);
				}else
				{
					openDia('提示信息',ret.msg);
				}
			},
			error:function(){
				
			}
		});
	}
	
	/*取消加入*/
	function applyJoinCfmCcl()
	{
		$("#confimDiv")[0].style.display = 'none';
	}
	function searchCode()
	{
		var code = $("#search").val();
		if(hasBlank(code))
		{
			$("#errorMsgDiv").html('请不要输入空格');
			return;
		}
		if(isNull(code))
		{
			$("#errorMsgDiv").html('请输入邀请码');
			return;
		}else
		{
			//window.theform.submit();
			to('${urlBasePath }weixin/user/companyInvestInput.do?code='+code);
		}
	}
</script>

</body>
</html>

